﻿using Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace FlowerDAL
{
    public class AdminDAL : IAdmin
    {
        #region 管理员登录
        public T AdminLogin<T>(string name , string pwd)
        {
            return DBHelper.AdminLogin<T>(name , pwd);
        }
        #endregion

        #region 客户管理
        //客户管理
        public List<T> UsersList<T>()
        {
            return DBHelper.GetList<T>();
        }

        //修改客户的状态
        public int UpdateState(int state , int id)
        {
            if (state == 1)
            {
                state = 0;
            }
            else
                state = 1;

            string sql = "update Users set Istrue=" + state + " where Id=" + id;
            return DBHelper.ExecuteNonQuery(sql);
        }
        #endregion

        #region 显示员工信息
        /// <summary>
        /// 显示员工信息
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public List<T> Employ<T>()
        {
            return DBHelper.GetList<T>();
        }
        #endregion

        #region 显示角色
        /// <summary>
        /// 显示角色
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public List<T> role<T>()
        {
            return DBHelper.GetList<T>();
        }
        #endregion

        #region 添加员工信息
        /// <summary>
        /// 添加员工信息
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="emp"></param>
        /// <returns></returns>
        public bool AddEmploy<T>(Employee emp)
        {
            return DBHelper.InsertEntity<Employee>(emp);
        }
        #endregion

        #region 修改状态0代表停用,1代表正常
        /// <summary>
        /// 修改状态0代表停用,1代表正常
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="emp"></param>
        /// <returns></returns>
        public int UpdateEmp<T>(int state , int id)
        {
            if (state == 1)
            {
                state = 0;
            }
            else
                state = 1;

            string sql = "update Employee set IsState=" + state + " where Id=" + id;
            return DBHelper.ExecuteNonQuery(sql);
        }
        #endregion
    }
}
